<template>

  <div id="app-container">
    <p></p>
    <router-link :to="'/account/levelAdd'">
      <el-button type="primary" >添加等级</el-button>
    </router-link>
    <!--数据显示列表-->
    <el-table ref="multipleTable" :data="dataList" border tooltip-effect="dark" style="width: 100%" >
      <el-table-column type="index" label="序号" width="70"/>
      <el-table-column prop="name" label="等级名称" width="100" ></el-table-column>
      <el-table-column prop="price" label="价格" width="100" ></el-table-column>
      <el-table-column prop="discount" label="折扣 " width="500" >
        <template slot-scope="scope">
          <span>{{scope.row.discount*100}}%</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <router-link :to="'/account/levelEdit/'+scope.row.id">
            <el-button type="success" size="mini" icon="el-icon-edit">编辑</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="handleDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import level from "../../../api/level";
export default {
  data(){
    return {
      dataList:[],
    }
  },
  created() {
    this.getList();
  },
  methods:{
    getList(){
      level.getList().then(res=>{
        this.dataList = res.data
        this.total = res.data.total
      })
    },
    handleDelete(id){
      this.$confirm("是否确定删除数据？", "提示", {type: 'warning'})
        .then(() => {
          level.delete(id).then(res=>{
            this.$message.success(res.message);
            this.currentPage = (this.total-1) % this.pageSize == 0 ? this.currentPage-1 : this.currentPage
            //当页数小于为0 就给它为1页 否则就还是当前页
            this.currentPage = this.currentPage < 1 ? 1 : this.currentPage
            this.getList();
          })
        })
        .catch(() => {
          // 表示点击了取消
          this.$message.info("取消删除操作");
        });
    },
  }
}
</script>
